<?php

namespace app\common\model;

use think\Model;


class UserCouponsLog extends Model
{

    

    

    // 表名
    protected $name = 'user_coupons_log';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text',
    ];


    public function getTypeList()
    {
     return ['send'=>'系统赠送','use'=>'使用','buy'=>'购买','back'=>'退回'];
    }



    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function coupons()
    {
        return $this->belongsTo('app\common\model\Coupons', 'coupons_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

}
